package com.example.smartcity_poverty.ui.AllService.SeeMovie.adapter

import android.content.Intent
import com.example.smartcity_poverty.App.Companion.url
import com.example.smartcity_poverty.Base.BaseRecyclerAdapter
import com.example.smartcity_poverty.logic.ServiceBean.LivingPayment.SmHomeListAllModel
import com.example.smartcity_poverty.logic.util.Util.glide
import com.example.smartcity_poverty.ui.AllService.SeeMovie.activity.SmShowActivity
import kotlinx.android.synthetic.main.re_sm_home_list.*

/**
 *  created by ikun
 *  ANDROID STUDIO - version 4.0
 *  email: jinkunwei41@gmail.com
 * --------------------------------
 *  看电影主页列表适配器
 **/
class SmHomeListAdapter(
    val size: Int,
    val list: MutableList<SmHomeListAllModel.RowsBean>,
    layoutId: Int
) : BaseRecyclerAdapter<SmHomeListAllModel.RowsBean>(list, layoutId) {
    override fun setData(
        view: BaseViewHolder.ViewFind,
        data: SmHomeListAllModel.RowsBean,
        position: Int,
        holder: BaseViewHolder
    ) {
        val d = list[position]
        val fv = holder.viewFind
        val con = holder.viewFind.view?.context

        // 填充数据
        glide(url + d.cover, fv.smHomeListImage)
        fv.smHomeListName.text = d.name
        fv.smHomeListTime.text = d.playDate

        // 点击进入电影详情页
        holder.itemView.setOnClickListener {
            con?.startActivity(
                Intent(con, SmShowActivity::class.java).putExtra(
                    "id",
                    d.id.toString()
                )
            )
        }
    }

    override fun getItemCount(): Int = size
}